﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

namespace Kevin.Framework.Validation
{
    internal abstract class ValueAccess
    {
        public abstract object GetValue(object target);
    }

    internal class PropertyValueAccess : ValueAccess
    {
        private PropertyInfo propertyInfo;

        public PropertyValueAccess(PropertyInfo pi)
        {
            this.propertyInfo = pi;
        }

        public override object GetValue(object target)
        {
            return this.propertyInfo.GetValue(target, null);
        }
    }

    internal class FieldValueAccess : ValueAccess
    {
        private FieldInfo fieldInfo;

        public FieldValueAccess(FieldInfo fi)
        {
            this.fieldInfo = fi;
        }

        public override object GetValue(object target)
        {
            return this.fieldInfo.GetValue(target);
        }
    }
}
